package com.sgb.kjwl.viewmodel.self.website;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.self.WebsiteDeleteEntity;
import com.sgb.kjwl.model.entity.self.WebsitePhotoEntity;
import com.sgb.kjwl.repository.SelfRepertory;
import com.sgb.kjwl.view.ui.activity.self.websiteManage.WebsitePhotoEditActivity3;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class WebsitePhotoEditModel3 extends BaseViewModel {

    private WebsitePhotoEditActivity3 activity;
    private SelfRepertory repertory;

    public WebsitePhotoEditModel3(WebsitePhotoEditActivity3 activity3, SelfRepertory tr){
        this.activity = activity3;
        this.repertory = tr;
    }

    public void deletePhotoData(List<WebsitePhotoEntity> id){
        WebsiteDeleteEntity en = new WebsiteDeleteEntity();
        List<String> ll = new ArrayList<>();
        for(WebsitePhotoEntity entity:id){
            ll.add(entity.getId());
        }
        en.setIds(ll);

        DialogHelper.showProgressDialog(activity, null, "获取信息中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getMailListAPI().deleteWebsitePhoto(en).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    EventBus.getDefault().post("delete_website_photo");
                    activity.finish();
                } else {
                    MToast.showToast(activity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                t.printStackTrace();
                DialogHelper.dismissProgressDialog();
            }
        });
    }
}
